package com.dzt.androidnewui.activity;

import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.Glide;
import com.dzt.androidnewui.R;
import com.dzt.androidnewui.databinding.ActivityAboutBinding;
import com.dzt.androidnewui.utils.BaseTools;
import com.dzt.androidnewui.utils.CommonUtils;
import com.dzt.androidnewui.utils.PerfectClickListener;

public class AboutActivity extends BaseActivity<ActivityAboutBinding> {

	private static String string_url_update_log = "http://jingbin.me/2016/12/30/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97-%E4%BA%91%E9%98%85/";

	@Override
	protected int getLayoutId() {
		return R.layout.activity_about;
	}

	@Override
	protected void initWidgets() {
		showContentView();
		setTitle(getString(R.string.about));
		bindingView.tvVersionName.setText("当前版本 V" + BaseTools.getVersionName());

		// 直接写在布局文件里会很耗内存
		Glide.with(this).load(R.mipmap.ic_launcher).into(bindingView.ivIcon);
		bindingView.tvGankio.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
		bindingView.tvGankio.getPaint().setAntiAlias(true);//抗锯齿
		bindingView.tvDouban.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
		bindingView.tvDouban.getPaint().setAntiAlias(true);//抗锯齿

		initListener();
	}

	@Override
	protected void initParams(Bundle savedInstanceState) {

	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}

	private void initListener() {
		bindingView.tvGankio.setOnClickListener(listener);
		bindingView.tvDouban.setOnClickListener(listener);
		bindingView.tvAboutStar.setOnClickListener(new PerfectClickListener() {
			@Override
			protected void onNoDoubleClick(View v) {
				BaseTools.openLink(v.getContext(), CommonUtils.getString(R.string.string_url_cloudreader));
			}
		});
		bindingView.tvFunction.setOnClickListener(new PerfectClickListener() {
			@Override
			protected void onNoDoubleClick(View v) {
				BaseTools.openLink(v.getContext(), string_url_update_log);
			}
		});
		bindingView.tvNewVersion.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				BaseTools.openLink(v.getContext(), CommonUtils.getString(R.string.string_url_new_version));
			}
		});
	}

	private PerfectClickListener listener = new PerfectClickListener() {
		@Override
		protected void onNoDoubleClick(View v) {
			String url = null;
			switch (v.getId()) {
				case R.id.tv_gankio:
					url = CommonUtils.getString(R.string.string_url_gankio);
					break;
				case R.id.tv_douban:
					url = CommonUtils.getString(R.string.string_url_douban);
					break;
				case R.id.tv_about_star:
					url = CommonUtils.getString(R.string.string_url_cloudreader);
					break;
				case R.id.tv_function:// 更新日志
					url = string_url_update_log;
					break;
			}
			//WebViewActivity.loadUrl(v.getContext(), url, "加载中...");
		}
	};
}
